function pos=rand_pos_in_boundary(bnd)
% rand_pos_in_boundary: Generate a random position in specified boundary
%
% SYNTAX:
%   pos = rand_pos_in_boundary(bnd)
%   Return generated random position.
%   Boundary object bnd should be created with function NEWBOUNDARY.

%   Author: Hongbin Ma
%   Last updated: 2009-6-2 with MATLAB 6.5
%   Problems or suggestions? Email me: mathmhb[at]163.com

if isempty(bnd),
    pos=rand(1,2);
    return;
end;
m=size(bnd.nodes);
xx=bnd.nodes(:,1);
yy=bnd.nodes(:,2);
w=rand(1,m);
pos=[w*xx,w*yy]/sum(w);
